const jwt = require('jsonwebtoken')
const expiresIn = 60 * 60 * 24 * 7 //自动记录当前时间，再加上这个
const SECRET = 'wucan zix'

// 签名
function sign(payload, options = {}) {
  const token = jwt.sign(payload, SECRET, Object.assign({
      expiresIn: expiresIn // 设置过期时间
  }, options))
  return token
}
const signed = sign({name: 'zix'})

//验证
function verify(token) {
  try {
    return  jwt.verify(token, SECRET)
  }catch(e) {
    console.log(e.message)
    return null
  }
}

module.exports = {
  verify,
  sign
}